

$(function () {

    $("#top").load('top.html');
    $("#left").load('office_left.html',function () {
        menuActive(0,1);
    });

    var queryParam = {
        userId: sessionStorage.getItem('userId')
    }
    requests.postReq(urls.worksList,JSON.stringify(queryParam),querySucc,null);

    function querySucc(data) {
        if(data.status == 1){
            var items = data.data;
            var worksListHtml = '';
            $.each(items,function (i,val) {
                worksListHtml += '<tr>' +
                    '<td>'+compTime(val.lastUpdateTime)+'</td>'+
                    '<td>'+val.publisher+'</td>'+
                    '<td>'+compTermYear(val.schoolYear,val.semester)+'</td>'+
                    '<td>'+val.workloadQuantity+'</td>'+
                    '<td><span class="edit_works" data-id="'+val.workloadId+'">编辑</span></td>'+
                    '</tr>';
            })
            $("#works_list").html(worksListHtml);
        }else{
            showTip(data.message);
        }
    }
    var workId = '';
    $("#works_list").on('click','.edit_works',function () {
        workId = $(this).attr('data-id');
        var tds = $(this).parents('tr').children('td');
        $("#works_term").html(tds.eq(2).html());
        $("#works_num").val(tds.eq(3).html());
        $("#editBox").show();
    })
    $("#updateInfo").click(function () {
        var updateParam = {
            'workloadId':workId,
            'workloadQuantity':$("#works_num").val()
        }
        if(! $.trim(updateParam.workloadQuantity)){
            showTip('请填写正确的工作量');
            return
        }
        requests.postReq(urls.editWorks,JSON.stringify(updateParam),function (data) {
            if(data.status == 1){
                showTip('基本教学工作量修改成功',function () {
                    location.reload();
                });
            }else{
                showTip(data.message);
            }
        })
    })

})